<template>
  <div class="app-container">

      
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
        <el-input v-model="blogQuery.title" placeholder="文章标题"/>
        </el-form-item>

        <el-form-item label="作者">
        <el-select
            v-model="blogQuery.author"
            placeholder="请选择">

            <el-option
                v-for="author in authorList"
                :key="author.id"
                :label="author.nickname"
                :value="author.id"/>

        </el-select>
        </el-form-item>

        <el-form-item>
         <el-select v-model="blogQuery.status" clearable placeholder="发布状态">
          <el-option :value='this.Normal' label="已发布"/>
          <el-option :value='this.Draft' label="未发布"/>
        </el-select>
        </el-form-item>
    
      <el-form-item label="添加时间">
        <el-date-picker
          v-model="blogQuery.begin"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      element-loading-text="数据加载中"
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="title" label="标题" width="160"  align="center" />
      <el-table-column prop="nickname" label="作者" width="120"  align="center" />

      <el-table-column label="分类"  width="150"  align="center" >
          
          <template slot-scope="scope">
           {{ scope.row.subjectLevelOne}}——{{ scope.row.subjectLeveTwo}} 
           </template>
       </el-table-column>
      <el-table-column label="评论状态"  align="center" width="100" >
          <template slot-scope="scope">
          {{ scope.row.commentStatus===0?'可评论':'不可评论' }} <!-- 得到每行的值进行判断  ===类型也匹配-->
        </template>
      </el-table-column>
      <el-table-column label="文章状态"  align="center" width="100">
          <template slot-scope="scope">
          {{ scope.row.status==Draft?'未发布':'已发布' }} <!-- 得到每行的值进行判断  ===类型也匹配-->
        </template>
      </el-table-column>
      <el-table-column prop="created" label="添加时间"   align="center"/>
      <el-table-column label="文章内容" width="120"  align="center" >
        <template slot-scope="scope">
             <!-- 查看 TODO -->
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="open(scope.row.content)">查看</el-button>
        </template>
      </el-table-column>

      
      <!-- <el-table-column prop="sort" label="排序" width="60" /> -->

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/blog/info/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <!-- 清除 TODO -->
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
        :current-page="page"
        :page-size="limit"
        :total="total"
        style="padding:30px 0;text-align:center;"
        layout="total,prev,pager,next,jumper"
        @current-change="getList" 
       />

  </div>





</template>
<script>
import blog from  '@/api/tingting/blog'
import subject from  '@/api/tingting/subject'
export default {
    data(){
        return{
        Normal:"Normal",
        Draft:"Draft",
        list:null,
        page:1,
        limit:4,
        total:0,
        blogQuery:{},
        authorList:{}
        }
    },
    created(){
        this.getList()
        this. getauthor()
    },
    methods:{
        getList(page = 1){
            this.page = page
            blog.getBlogList(this.blogQuery,this.page,this.limit)
              .then(response => {
                this.list=response.data.rows
                this.total=response.data.total
                console.log(this.list)
              })
        },
        getauthor(){
          blog.getListAuthor()
            .then(response =>{
              this.authorList=response.data.items
            })
        },
        resetData(){
            this.blogQuery={}
            this.getList()
        },

      //   open(content) {
      //   this.$alert(content, '内容', {
      //     dangerouslyUseHTMLString: true
      //   });
      // }
        //   removeDataById(id){

        //   this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        //   confirmButtonText: '确定',
        //   cancelButtonText: '取消',
        //   type: 'warning'
        //   }).then(() => {
        //     consumer.deleteConsumerId(id)
        //     .then(response => {
        //         this.$message({
        //         type: 'success',
        //         message: '删除成功!'
        //   });
        //         this.getList()
        //     })
         
        //  })

        // }
    }

}
</script>